[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
strrchr() Scan String for Last Occurrence of Character
#include <string.h> Required for declarations only
char *strrchr(string,ch);
const char *string; Search string
int ch; Character to be located
strrchr() scans 'string' in a reverse direction, looking for the last
occurrence of the character 'ch'. The terminating null character
('\0') is included in the search.
Returns: A pointer to the last occurrence of 'ch' in 'string'.
If the character is not found in 'string', a NULL
pointer is returned.
-------------------------------- Example ---------------------------------
The following statements find the last occurrence of 'ch' in
'string'.
#include <string.h>
#include <stdio.h>
char *string = "How now, brown cow.";
int ch = 'b';
char *rslt;
main()
{
if ((rslt = strrchr(string,ch)) != NULL)
{
printf("character found: %c\n",*rslt);
printf("%s\n",rslt);
}
else
printf("character not found.\n");
}
See Also:
strchr()
strpbrk()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson